<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>修改卖盘池</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="" name="description">
<meta content="" name="author">
<link href="${request.getContextPath()}/Public/assets/admin/css/css.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/jquery-ui/jquery-ui.min.css" rel="stylesheet" type="text/css">

<link href="${request.getContextPath()}/Public/assets/global/css/components-rounded.css" id="style_components" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/css/plugins.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/admin/css/layout.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/admin/css/themes/default.css" rel="stylesheet" type="text/css" id="style_color">
<link href="${request.getContextPath()}/Public/assets/admin/css/custom.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/admin/css/common.css" rel="stylesheet" type="text/css">



<link rel="shortcut icon" href="${request.getContextPath()}/Public/favicon.ico">
<!--[if lt IE 9]>
<script src="${request.getContextPath()}/Public/assets/global/plugins/respond.min.js"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/excanvas.min.js"></script>
<![endif]-->
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-migrate.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-ui/jquery-ui.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-validation/js/jquery.validate.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-validation/js/localization/messages_zh.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.blockui.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.cokie.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/uniform/jquery.uniform.min.js" type="text/javascript"></script>

<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.sparkline.min.js" type="text/javascript"></script>

<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js" type="text/javascript"></script>

<script src="${request.getContextPath()}/Public/assets/global/scripts/metronic.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/admin/scripts/layout.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/admin/scripts/commonUtils.js" type="text/javascript"></script>

<!-- select2控件 -->
<script type="text/javascript" src="${request.getContextPath()}/Public/assets/global/plugins/select2/select2.js"></script>
<script type="text/javascript" src="${request.getContextPath()}/Public/assets/global/plugins/select2/select2_locale_zh-CN.js"></script>
<link href="${request.getContextPath()}/Public/assets/global/plugins/select2/select2.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="${request.getContextPath()}/Public/js/common/util.js"></script>
<script type="text/javascript" src="${request.getContextPath()}/Public/My97DatePicker/WdatePicker.js"></script>
<!-- 数字小数点后两位工具类 -->
<script type="text/javascript" src="${request.getContextPath()}/Public/js/common/util.js"></script>
<style type="text/css">
    *
    {
        font-size: 14px;
    }
    #dataForm label.error
    {
        color: Red;
        font-size: 13px;
        margin-left: 5px;
        padding-left: 16px;
        background:  left no-repeat;
    }
    .commonBtn{
    	margin: 0 5px;
    }
    .normalBtn{
    	border: 1px solid #C0C1B4; color:#555; background-color:#fff;
    }
    
.ttLbl .radio {
	padding-top: 0;
}
</style>

</head>
<body class="page-header-top-fixed">
<div class="page-header">
	<!--头部开始-->
	<#include "/include/top.html" />
	<!-- 头部信息结束 -->

	<!-- 头部菜单开始 -->
	<#include "/include/top_menu.html" />
	<!-- 头部菜单结束 -->
</div>
<!-- END HEADER -->
<div class="page-container">
	<div class="page-content">
		<div class="container-fluid">
			<!-- 当前位置提示开始 -->
			<ul class="page-breadcrumb breadcrumb">
				<li>
					<a href="#">首页</a><i class="fa fa-circle"></i>
				<li class="active">
					 撮合管理<i class="fa fa-circle"></i>
				<li class="active">
					 修改卖盘池
			</ul>
			<div class="row margin-top-10">
				<div class="col-md-12">
					<div class="portlet light bordered">
						<form class="form-horizontal" id="dataForm">
						
						<!-- 修改的时候，判断是否发布 -->
						<input type="hidden" id="fabu" name="fabu" value="${fabu!''}">
						<!-- 仓库id -->
						<input type="hidden" id="wareId_pool" name="wareId_pool" value="${sellPool.wareId}">
		  		  		<input type="hidden" id="sellId" name="id" value="${sellPool.id!''}">
		  		  		
		  		  		<input type="hidden" name="prodId"  id="prodId" value="${prodId}"/>
				 	 	<input type="hidden" name="prodName" id="prodName" value="${prodName!''}"/>
				 	 	<!-- 挂盘ID --> 
				  		<input type="hidden" id="companyid" value="${companyid}">
				  		<!-- 品目ID-->
					   	<input type="hidden" id="itemId" value="${itemId}">
				  		 <input type="hidden" class="form-control" id="sortNums" name="sortNums" value="${sellPool.sortNum}">
			  			 <div class="form-group">
						    <label  class="col-sm-2 control-label">排序：</label>
						    <div class="col-sm-4">
						      <input type="text" class="form-control" id="sortNum" name="sortNum" value="${sellPool.sortNum}" onblur="checkSortNum(this)" style="width: 50px;height: 34px;" >
						      <span id="s1" style="color: red"></span>
						    </div>
						  </div>
				  		
						 <#list itemAttrList as itemAttr>
							  	<div class="form-group">
							  		<input type="hidden" name="arrtName" value="${itemAttr.name}">
							  		<input type="hidden" name="fillmode" value="${itemAttr.fillmode}">
							  		<input type="hidden" name="ids" value="${itemAttr.id?c}">
								    <label  class="col-sm-2 control-label">${itemAttr.name}：</label>
								    <div class="col-sm-2">
								    	<!-- 填写方式  文本框 -->
									    <#if itemAttr.fillmode?? && itemAttr.fillmode==0>
									    	<#list commodityAttrList as chCommodityAttrEntity> 
									    		<#if chCommodityAttrEntity.attrId == itemAttr.id>
									    			<input type="text" name="attrValue${itemAttr.id}" value="${chCommodityAttrEntity.attrValue}" class="form-control" />
									    		</#if> 
									    	</#list>
									    </#if>
									    <!-- 填写方式  下拉框-->
								     	<#if itemAttr.fillmode?? && itemAttr.fillmode==1>
								      		<select  class="form-control"  name="attrValue${itemAttr.id}">
								      			<#if itemAttr.optionsValue??>
					  								<#list itemAttr.optionsValue as optionsValue>
									      				<option value="${optionsValue!''}" 
										      				<#list commodityAttrList as chCommodityAttrEntity> 
										      					<#if chCommodityAttrEntity.attrValue == optionsValue> selected="selected" </#if>
									      					</#list>>${optionsValue}
									      				</option>
								      				</#list>
					  				  			</#if>
								      		<select>
								      		<#if itemAttr.mainproperty?? && itemAttr.mainproperty==1 >
								      		<font color="red">(*必填项)</font>
								      		</#if>
								      	</#if>
								      	<!-- 填写方式 复选框(此种方式舍弃) -->
								      	<#if itemAttr.fillmode?? && itemAttr.fillmode==2>
									   		 <#if itemAttr.optionsValue??>
						  						<#list itemAttr.optionsValue as optionsValue>								      		
													<input type="checkbox"  name="attrValue${itemAttr.id}" value="${optionsValue}" class="md-radiobtn" />
													<#if itemAttr.mainproperty?? && itemAttr.mainproperty==1 >
								      				<font color="red">(*必填项)</font>
								      				</#if>
													${optionsValue}
									      		</#list>
						  				 	 	</#if>
									    		</#if>						      	
								      	<!-- 填写方式  单选框(做成了下拉框)-->
								        <#if itemAttr.fillmode?? && itemAttr.fillmode==3>
									    	<#if itemAttr.optionsValue??>
									    	<select  class="form-control" name="attrValue${itemAttr.id}">
						  						<#if itemAttr.optionsValue??>
					  								<#list itemAttr.optionsValue as optionsValue>
									      				<option value="${optionsValue!''}" 
										      				<#list commodityAttrList as chCommodityAttrEntity> 
										      					<#if chCommodityAttrEntity.attrValue = optionsValue> selected="selected" </#if>
									      					</#list> > ${optionsValue}
									      				</option>
								      				</#list>
					  				  			</#if>
									      	
									      	</select  >	
									      	<#if itemAttr.mainproperty?? && itemAttr.mainproperty==1 >
								      		<font color="red">(*必填项)</font>
								      		</#if>
						  				 	 </#if>
								    	</#if>
								    </div>
							  	</div>
						  </#list>
					  	<div class="form-group">
						    <label  class="col-sm-2 control-label">库存：</label>
						    <div class="col-sm-4">
						      <input type="text" class="form-control" value="${sellPool.quantity}" id="quantity" name="quantity" style="width: 235px;height: 34px;" onblur="if(value == 0 ){value=''}"/>
						    </div>
					  	</div>
						  
					  	<div class="form-group">
						    <label  class="col-sm-2 control-label">仓库：</label>
						    <div class="col-sm-2">
						      <select class="form-control" id="wareProvince" name="wareProvince" onchange="selWareName();" style="width: 120px;height: 34px;">
							    	<#list arealist as area>
							    			<option value="${area.id}" <#if sellPool.wareProvince == area.id >selected</#if>  >${area.name}</option>
							    	</#list>
						      </select>
						    </div>
						    <div class="col-sm-2">
						      <!-- <select class="form-control" id="wareId" name="wareId" style="width: 120px;height: 34px;">
				    		  </select> -->
				    		  <input class="form-control" id="wareIds" name="wareIds">
				    		  <input type="hidden" class="form-control" id="wareId" name="wareId" value="${sellPool.wareId}">
						    </div>
					  	</div>
						  
					  	<div class="form-group">
						    <label  class="col-sm-2 control-label">价格：</label>
						    <div class="col-sm-4">
						      <input type="text" class="form-control" id="price" name="price" value="${sellPool.price}" style="width: 235px;height: 34px;"  onblur="if(value == 0 ){value=''}"/>
						    </div>
					  	</div>
						  
					  	<div class="form-group">
						    <label  class="col-sm-2 control-label">起订量：</label>
						    <div class="col-sm-2">
						       <input type="text" class="form-control" name="moq" id="moq"  value="${sellPool.moq!''}" 
						       	onfocus="if(value == 1){value=''}"   
                				onblur="if(value==''){value=1}"
                				onblur="if(value == 0 ){value=1}"
                				/>
                				
						    </div>
						    
						    <div class="col-sm-2">
						   		  <span class="changeUnit">吨</span>，超出部分按
						    </div>
						    
						    <div class="col-sm-2">
						     
						      <input name="outmoq"  id="outmoq" value="${sellPool.outmoq!''}" 
						       	onfocus="if(value == 1){value=''}"   
                				onblur="if(value == 0 ){value=1}"
						      type="text">
						    </div>
						    
						    <div class="col-sm-2">
						     	（<span class="changeUnit">吨</span>）整数倍递增
						    </div>
						    
					  	</div>
						  
					    <div class="form-group">
						    <label  class="col-sm-2 control-label">磅差(‰)：</label>
						    <div class="col-sm-2">
						       <input type="text" value="${sellPool.overflow!''}"  onblur="if(value == 0 ){value=2}" class="form-control" id="pounddiff" name="overflow">
						    </div>
					  	</div>
						  
					    <div class="form-group">
							<label class="col-sm-2 control-label">交货方式：</label>
							<div class="col-sm-1">
								<label class="ttLbl"><input type="radio"class="form-control" name="delivery" 
									value="2" <#if sellPool.delivery == 2 >checked="checked" </#if> > 买方自提</label>
							</div>
							<div class="col-sm-1">
								<label class="ttLbl"><input type="radio"class="form-control" name="delivery" 
									value="1" <#if sellPool.delivery == 1 >checked="checked" </#if> > 卖方送货</label>
							</div>
						</div>
						  
					  	<div class="form-group">
							<label class="col-sm-2 control-label">结算方式：</label>
							<div class="col-sm-1">
								<label class="ttLbl"><input type="radio" class="form-control" name="paytype" 
								value="1" <#if sellPool.paytype == 1 >checked="checked" </#if> >现款现汇</label>
							</div>
							<div class="col-sm-1">
								<label class="ttLbl"><input type="radio" class="form-control" name="paytype" 
								value="2" <#if sellPool.paytype == 2 >checked="checked" </#if> > 银行承兑</label>
							</div>
							<div class="col-sm-1">
								<label class="ttLbl"><input type="radio" class="form-control" name="paytype" 
									value="3" <#if sellPool.paytype == 3 >checked="checked" </#if> > 安全支付</label>
							</div>
						</div>
							
						    
		    			<div class="form-group">
							<label class="col-sm-2 control-label">付款方式：</label>
							<div class="col-sm-1">
								<label class="ttLbl"><input type="radio"class="form-control" name="receipttype" 
								value="1" <#if sellPool.receipttype == 1 >checked="checked" </#if>>款到发货</label>
							</div>
							<div class="col-sm-1">
								<label class="ttLbl"><input type="radio" class="form-control" name="receipttype" 
								value="2" <#if sellPool.receipttype == 2 >checked="checked" </#if>> 货到付款</label>
							</div>
						</div>
						  
				      	<div class="form-group">
						    <label  class="col-sm-2 control-label">交货日期：</label>
						    <div class="col-sm-2">
						       <input type="text" class="form-control" id="deliverytime" value="${sellPool.deliverytime}"  onClick="WdatePicker()" name="deliverytime">
						    </div>
					  	</div>
						   
					  	<div class="form-group">
						    <label  class="col-sm-2 control-label">计量单位：</label>
						    <div class="col-sm-4">
						      <select  class="form-control" id="unit" name="unit" style="width: 235px;height: 34px;" >
						      	<option value="0" <#if sellPool.unit == 0 > selected="selected" </#if> >吨</option>
					      		<option value="1" <#if sellPool.unit == 1 > selected="selected" </#if> >千克</option>
						      </select>
					    	</div>
					  	</div>
					  
					  <div class="form-group">
					    <label  class="col-sm-2 control-label">优先级：</label>
					    <div class="col-sm-4">
					      <select  class="form-control" id="priority" name="priority" style="width: 235px;height: 34px;" >
					      	<option value="0" <#if sellPool.priority == 0 > selected="selected" </#if> >高</option>
					      	<option value="1" <#if sellPool.priority == 1 > selected="selected" </#if> >中</option>
					      	<option value="2" <#if sellPool.priority == 2 > selected="selected" </#if> >低</option>
					      </select>
					    </div>
					  </div>
					  <div class="form-group">
					    <div class="col-sm-offset-2 col-sm-10">
					    	<button id="notSavetButton"  onclick="javascript :history.back(-1);" type="button" class="btn  green pull-left">
								返回 <i class="m-icon-swapright m-icon-white"></i>
							</button>
							
					      	<button type="button"  id="savetButton" class="btn green pull-center">
								修改<i class="m-icon-swapright m-icon-white"></i>
							</button>
					    </div>
					  </div>
					</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- 底部开始 -->
<#include "/include/foot.html" />
<!-- 底部结束 -->
</body>
<script>
	//计数器 
	var counter = 0;
	
	jQuery(document).ready(function() {
		//如果省不为空，则初始化仓库
		selWareName();
		
	   	Metronic.init(); // init metronic core componets
	   	Layout.init(); // init layout
	   	checkNum($('#price'));
	  
	   	//品目银,在新建卖盘的时候默认计量单位为千克
	    if ($("#itemId").val() == 26288) {
			$(".changeUnit").text("千克");
			$("#unit").val("1").selected = true;
		}
	   	//单位 
	   	$(".changeUnit").each(function(index, element){
			$(element).text($("#unit :selected").text());
		});
	   	
		$("#unit").change(function(){
			$(".changeUnit").each(function(index, element){
				$(element).text($("#unit :selected").text());
			});
		});
		
		checkNum5($('#quantity'));
		checkNum5($('#moq'));
		checkNum5($('#outmoq'));
	});
	recordDate();
	//初始化日期
	function recordDate() {
		var nowDate = new Date();
        //$('#date-picker').attr("date-date",nowDate.getFullYear()+"/"+parseInt(nowDate.getMonth()+1)+"/"+nowDate.getDate());
        $('.date-picker').datepicker({
    	    autoclose: true	   
    	});
	}
	
	$("#savetButton").bind("click",function(){
		var  num=/^[0-9]+([.]{1}[0-9]+){0,1}$/;
		var quantity=Number($("#quantity").val());
		var price=Number($("#price").val()).toFixed(2);
		var pounddiff=$("#pounddiff").val();
		var outmoq=$("#outmoq").val();
		var moq=$("#moq").val();
		
		if(quantity<=0 ){
			alert("库存必须大于0的数");
			return ;
			
		}
		
		var num1=/[0-9]*[1-9][0-9]*/;
		if(!num1.test(outmoq) || outmoq<=0){
			alert("递增量必须为正整数");
			return ;
			
		}
		if(!num.test(pounddiff) || pounddiff<=0){
			alert("磅差必须大于0的数");
			return ;
			
		}
		
		if(!$("#dataForm").validate({
			//数据验证
			rules:{
				companyid:"required",
				wareName:"required" ,
				wareProvince:"required",
				wareIds:"required",				
				priority:"required",
				unit:"required",
				deliverytime:"required",
			}
		
		}).form()){
			return;
		} 
		
		var paytype = $("input[name='paytype']:checked").val();
		if(paytype==3){
			//安全支付 
			var customerId=$("#companyid").val();
			var checkUserPay;
			$.ajax({
				url : "${request.getContextPath()}/dealMake/checkUserPay.do",
				type : "post",
				dataType:"json",
				async: false,
				data :{"customerId":customerId}, //联动查询的字符
				success : function(data) {
					if(data == 1){
						alert("这家企业没有有色网商城支付账号，无法进行安全支付！");
						checkUserPay = false;
					}
				}
			});
			if (checkUserPay == false) {
				return;
			}
		} 
		$.ajax({
			url : "${request.getContextPath()}/dealMake/updateSellPool_new.do",
			type : "post",
			dataType:"json",
			async: false,
			data : $("#dataForm").serialize(),
			success : function(result) {
			   	if(result.code=="ok"){
				   	alert(result.msg);
		      		window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
				}else{
		   			alert(result.msg);	
		   			window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
		   		}
		   }
		});
	});
	
	function selWareName(){
		var value = $("#wareProvince").val();
		$("#wareIds").empty();
		$("#wareIds").val(0);//select2必须有一个值才能初始化 
		if(value==-1){
			var ops =  document.getElementById("wareIds").options;
			ops.length=0;
			ops.add(new Option("请选择仓库",""));
			return;
		}
		//仓库模糊搜索
		$("#wareIds").select2({// 
		   language: "zh_CN",
	       placeholder: "搜索仓库",//文本框的提示信息
	       minimumInputLength: 0,//至少输入n个字符，才去加载数据
	       allowClear: true, //是否允许用户清除文本信息
	       ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
	    	   url : "${request.getContextPath()}/dealMake/selWarehouseByAreaBlur.do",
	           dataType: 'json',//接收的数据类型
	           type : "post",
	           data: function (term, page) {//在查询时向服务器端传输的数据
	               return {
	            	   wareName:term, //联动查询的字符
	            	   areaId : value,
	            	   companyName:$("#companyName").val(),
	                   page: 10 //一次性加载的数据条数
	               };
	           },
	           results: function (data, page) { // parse the results into the format expected by Select2.
	               // since we are using custom formatting functions we do not need to alter remote JSON data
	               var realNames = new Array();    
	                    for (var i = 0; i < data.length; i++) {
	                         realNames.push({id: data[i].id, text: data[i].name});
	                         
	                  }
	               return {results: realNames};
	           }
	       	},
	       	initSelection: function(element, callback) {//加载初始化
				var wareId_pool = $("#wareId_pool").val();
	       		if(counter < 1){
	       			if (wareId_pool != "") {
						$.ajax("${request.getContextPath()}/dealMake/initWareHouse.do?wareId="+wareId_pool).done(function(data) { 
							callback({id:data.id,text:data.name}); 
						});
					}
					counter++;
	       		}
			},
	       	formatResult: resultFormatResult, // omitted for brevity, see the source of this page
	       	formatSelection: resultFormatSelection,  // omitted for brevity, see the source of this page
	       	dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
	       	escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
    	});
	}
	
	function resultFormatResult(medata) {
		//$("#wareId").val(medata.id);
        return medata.text; 
	} 
	      
	function resultFormatSelection(medata) {
		$("#wareId").val(medata.id);
        return medata.text; 
	}
	
	
	
	//编号是否为正整数   
	function checkSortNum(object){
		var re = /^[0-9]*[0-9][0-9]*$/ ; 
		var temp = re.test(object.value);
		if(temp != true){//不是正整数
			alert("只能输入0-99的正整数！");
			$(object).val($("#sortNums").val());
		}
		if(object.value > 99){
			alert("只能输入0-99的正整数！");
			$(object).val($("#sortNums").val());
		}
	}

</script>
</html>

